package com.wangjiang.mario.admin.web.admin.controller.v1;

import com.wangjiang.mario.admin.common.base.BaseController;
import com.wangjiang.mario.admin.common.object.UUidList;
import com.wangjiang.mario.admin.common.object.UUidListForBatchUpdate;
import com.wangjiang.mario.admin.common.rest.ResultGenerator;
import com.wangjiang.mario.admin.common.rest.entity.Result;
import com.wangjiang.mario.admin.system.domain.entity.SystemDeptEntity;
import com.wangjiang.mario.admin.system.domain.service.SystemDeptService;
import com.wangjiang.mario.admin.system.object.dept.SystemDeptQo;
import com.wangjiang.mario.admin.system.object.dept.SystemDeptVo;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 部门管理
 *
 * @author  wangjiang
 * @Date 2019-08-28 15:33:59
 */
@RestController
@RequestMapping("/systemDept")
@Api(value = "/systemDept", tags = "部门管理")
public class SystemDeptController extends BaseController<SystemDeptEntity> {

    private static final Logger logger = LoggerFactory.getLogger(SystemDeptController.class);

    @Autowired
    private SystemDeptService systemDeptService;

    @GetMapping("/tree")
    public Result tree (SystemDeptEntity qo) {
        return ResultGenerator.genSuccessResult(baseService.tree(qo));
    }

    @GetMapping("")
    public Result list (
            SystemDeptQo qo,
            @RequestParam(name = "currentPage", defaultValue = "1") Integer currentPage,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize
    ) {
        return ResultGenerator.genSuccessResult(baseService.basePage(currentPage, pageSize, qo, SystemDeptVo.class));
    }

    /**
     * 根据uuid 获取实体信息
     *
     * @param uuid
     * @return
     */
    @GetMapping("/{uuid}")
    public Result getOne (@PathVariable String uuid) {
        return ResultGenerator.genSuccessResult(baseService.baseGetByUUid(uuid, SystemDeptVo.class));
    }

    @GetMapping("/all")
    public Result all (SystemDeptEntity qo) throws IllegalAccessException {
        return ResultGenerator.genSuccessResult(baseService.list(qo));
    }

    @PostMapping("")
    public Result create (@RequestBody SystemDeptEntity entity) {
        return ResultGenerator.genSuccessResult(baseService.baseSave(entity));
    }

    @PutMapping("")
    public Result update(@RequestBody SystemDeptEntity entity) {
        return ResultGenerator.genSuccessResult(baseService.baseUpdateById(entity));
    }

    @PutMapping("/batch")
    public Result batchUpdate(
            @RequestBody UUidListForBatchUpdate<SystemDeptEntity> uuidListForBatchUpdate
    ) {
        return ResultGenerator.genSuccessResult(baseService.baseUpdateBatch(uuidListForBatchUpdate));
    }

    @DeleteMapping("")
    public Result delete(
            @RequestParam String id
    ) {
        return ResultGenerator.genSuccessResult(baseService.baseSoftRemoveById(id));
    }

    @DeleteMapping("/batch")
    public Result batchDelete(
            @RequestBody UUidList uuidList
    ) {
        return ResultGenerator.genSuccessResult(baseService.baseBatchSoftRemoveByUUidList(uuidList));
    }
}
